package com.example.administrator.shzs.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.administrator.shzs.R;
import com.example.administrator.shzs.entity.OrderAll;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * 订单详情（用户评价页面）
 * Created by Administrator on 2016/11/27.
 */

public class StayEvaluateAdapter extends RecyclerView.Adapter<StayEvaluateAdapter.StayViewHoder> {

        //全部订单使用的同一个实体类
    private List<OrderAll> datalist;

    private Context context;

    public StayEvaluateAdapter(List<OrderAll> datalist, Context context) {
        this.datalist = datalist;
        this.context = context;
    }

    public interface StayEvaluate {
        void Onclick(View view, int postion, int po,String ivShopImage);
    }

    private StayEvaluate stayEvaluate;

    public void setStayEvaluate(StayEvaluate listent) {
        this.stayEvaluate = listent;
    }


    @Override
    public StayEvaluateAdapter.StayViewHoder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = View.inflate(context, R.layout.xrecyclerview_stay_evaluate_item, null);

        StayEvaluateAdapter.StayViewHoder hoder = new StayEvaluateAdapter.StayViewHoder(view);

        return hoder;
    }

    @Override
    public void onBindViewHolder(final StayEvaluateAdapter.StayViewHoder holder, final int position) {

        holder.tvMoney.setText(datalist.get(position).getTotalPrice());

        final String ivShopImage= datalist.get(position).getIcon();
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.mipmap.user)
                .showImageForEmptyUri(R.mipmap.user)
                .showImageOnFail(R.mipmap.user)
                .cacheInMemory(true)
                .cacheOnDisk(true)
                .build();

        ImageLoader.getInstance().displayImage(datalist.get(position).getIcon(),
                holder.ivShopImage,
                options
        );

        holder.tvOnMoreOrder.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                stayEvaluate.Onclick(holder.tvOnMoreOrder, position, 0,ivShopImage);
            }
        });

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                stayEvaluate.Onclick(holder.itemView, position, 1,ivShopImage);
            }
        });

        holder.evaluate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                stayEvaluate.Onclick(holder.evaluate,position,2,ivShopImage);
            }
        });

        holder.tvShopName.setText(datalist.get(position).getTogoName());

    }


    @Override
    public int getItemCount() {
        return datalist == null ? 0 : datalist.size();
    }

    public class StayViewHoder extends RecyclerView.ViewHolder {

        private TextView tvShopName;//商家名
        private TextView tvCommodity;//商品名称
        private TextView tvNumber;//商品数量 x1
        private TextView tvTotalNumber;//总数量
        private TextView tvMoney;//金额

        private TextView evaluate;//评价
        private TextView tvOnMoreOrder;//再来一单
        private CircleImageView ivShopImage;//商家图片


        public StayViewHoder(View itemView) {
            super(itemView);

//            mSwipeSwitch= itemView.findViewById(R.id.content_view);
            tvNumber = (TextView) itemView.findViewById(R.id.tv_number_all_order);
            tvShopName = (TextView) itemView.findViewById(R.id.tv_shopName_all_order);
            tvCommodity = (TextView) itemView.findViewById(R.id.tv_commodity_all_order_item);
            tvTotalNumber = (TextView) itemView.findViewById(R.id.tv_Toatalnumber_all_order);
            tvMoney = (TextView) itemView.findViewById(R.id.tv_money);
            ivShopImage = (CircleImageView) itemView.findViewById(R.id.iv_shopImage_all_order_item);
            evaluate = (TextView) itemView.findViewById(R.id.tv_Evaluate);
            tvOnMoreOrder = (TextView) itemView.findViewById(R.id.tv_one_more_order);
        }
    }
}
